﻿#include "config.h"
#include <QtCore/QtCore>
#include <QDebug>

Config::Config(QString qstrfilename)
{
    if (qstrfilename.isEmpty())
    {
        m_qstrFileName = QCoreApplication::applicationDirPath() + "/Config.ini";
    }
    else
    {
        m_qstrFileName = qstrfilename;
    }

    QFileInfo fileInfo(m_qstrFileName);
    if(!fileInfo.exists())
    {
          InitConfig();
    }
    m_psetting = new QSettings(m_qstrFileName, QSettings::IniFormat);
    qDebug() << m_qstrFileName;
}


Config::~Config()
{
    delete m_psetting;
    m_psetting = nullptr;
}


void Config::SetValue(QString qstrnodename,QString qstrkeyname,QVariant qvarvalue)
{
    m_psetting->setValue(QString("/%1/%2").arg(qstrnodename).arg(qstrkeyname), qvarvalue);
}

QVariant Config::GetValue(QString qstrnodename,QString qstrkeyname)
{
    QVariant qvar = m_psetting->value(QString("/%1/%2").arg(qstrnodename).arg(qstrkeyname));
    return qvar;
}

void Config::InitConfig()
{
    SetValue("Display","TextColor","#F0F0F0");
    SetValue("Display","PanelColor","#F0F0F0");
    SetValue("Display","BorderColor","#F0F0F0");
    SetValue("Display","NormalColorStart","#F0F0F0");
    SetValue("Display","NormalColorEnd","#F0F0F0");
    SetValue("Display","DarkColorStart","#F0F0F0");
    SetValue("Display","DarkColorEnd","#F0F0F0");
    SetValue("Display","HighColor","#F0F0F0");
    SetValue("listener","port",7599);
    SetValue("listener","minThreads",4);
    SetValue("listener","maxThreads",100);
    SetValue("listener","cleanupInterval",60000);
    SetValue("listener","readTimeout",60000);
    SetValue("listener","maxRequestSize",16000);
    SetValue("listener","maxMultiPartSize",10000000);
}
